<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">创建自动发放方案</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
               :pagination="ipagination" :loading="loading"
               class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="statusSlot" slot-scope="text">
          <a-tag color="green" v-if="text==1">
            正常
          </a-tag>
          <a-tag color="red" v-else>
            失效
          </a-tag>
        </template>


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="record.status==1">编辑</a>
          <a @click="handleDetail(record)" v-if="record.status==0">查看</a>
          <a-divider type="vertical"/>
          <a-popconfirm v-if="record.status==0" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-popconfirm v-if="record.status==1" title="确定失效吗?" @confirm="() => handleDelete1(record)">
            <a>失效</a>
          </a-popconfirm>

        </span>

      </a-table>
    </div>

    <mms-coupon-auto-send-modal ref="modalForm" @ok="modalFormOk"></mms-coupon-auto-send-modal>
  </a-card>
</template>

<script>
import {putAction} from '@/api/manage'
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import MmsCouponAutoSendModal from './modules/MmsCouponAutoSendModal'

export default {
  name: 'MmsCouponAutoSendList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MmsCouponAutoSendModal
  },
  data() {
    return {
      description: '优惠券发放设置管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '触发事件',
          align: "center",
          dataIndex: 'event_dictText'
        },
        {
          title: '优惠券',
          align: "center",
          dataIndex: 'couponId'
        },
        {
          title: '发放次数限制',
          align: "center",
          dataIndex: 'sendTimes',
          customRender: function (text) {
            return text == 0 ? "不限" : text
          }
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: "statusSlot"},
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/mallPlus/mmsCouponAutoSend/list",
        delete: "/mallPlus/mmsCouponAutoSend/delete",
        deleteBatch: "/mallPlus/mmsCouponAutoSend/deleteBatch",
        exportXlsUrl: "/mallPlus/mmsCouponAutoSend/exportXls",
        importExcelUrl: "mallPlus/mmsCouponAutoSend/importExcel",

      },
      dictOptions: {},
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleDelete1: function (item) {
      item.status = 0
      var that = this
      putAction("/mallPlus/mmsCouponAutoSend/edit", item).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>